﻿
@{
    ViewBag.Title = "PrescriptionForm";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style>
    .table-responsive {
        border: 0px solid #ddd;
    }
</style>

<form>
    <div style="border-bottom:1px solid rgb(221, 221, 221);">
        <table class="form">
            <tr>
                <th class="formTitle">病历号：</th>
                <td class="formValue">
                    <input id="blh" name="blh" type="text" class="form-control" placeholder="请输入病历号" />
                </td>
                <th class="formTitle">姓名：</th>
                <td class="formValue">
                    <input id="xm" name="xm" type="text" class="form-control" placeholder="请输入姓名" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">开始时间：</th>
                <td class="formValue">
                    <input id="kssj" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                </td>
                <th class="formTitle">结束时间：</th>
                <td  class="formValue">
                    <input id="jssj" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                </td>
                <td class="formValue">
                    <input type="button" id="btn_search" class="btn btn-primary" style="margin-left: 60px;" value="查询" />
                </td>
            </tr>
        </table>
    </div>
    <!--处方信息 包括卡号 病历号 姓名 -->
    <div id="prediv" class="gridPanel" style="margin-top:1%; margin-left:1%">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</form>

<script>

    //上一个window对象
    var prevWindow;

    var from = $.request("from");
    if (!!from) {
        prevWindow = top.top.frames[from];
    }
    else {
        prevWindow = $.currentWindow();
    }

    $(function () {
        var obj = new Object;
        obj.blh = $.request("blh");
        obj.kssj = $.request("kssj");
        obj.jssj = $.request("jssj");
        var searInfo = new preSearchInfo();
        //加载数据
        searInfo.init(obj);

        //查询
        $("#btn_search").click(function () {
            $("#gridList").jqGrid('setGridParam', {
                postData: { blh: $("#blh").val(), xm: $("#xm").val(), kssj: $("#kssj").val(), jssj: $("#jssj").val(), r: Math.random() },
            }).trigger('reloadGrid');
        });
    });

    var preSearchInfo = (function () {
        //加载列表
        var loadGrid = function (data) {
            var $gridList = $("#gridList");
            $gridList.newtouchLocalDataGrid({
                height: $(window).height() - 200,
                //autowidth: false,
                //width: $("#prediv").width() - 2,
                //url: "///?"+ Math.random(),
                //postData: { blh: $("#blh").val(), xm: $("#xm").val() },
                caption: '处方列表',
                unwritten: false,
                colModel: [
                    { label: '处方号', name: 'cfh', width: 150, align: 'left' },
                    { label: '金额', name: 'je', width: 120, align: 'left' },
                    { label: '医生', name: 'ys', width: 100, align: 'left' },
                    { label: '开立时间', name: 'CreateTime', width: 120, align: 'left' }
                ],
                pager: "#gridPager",
                sortname: 'CreateTime desc',
                viewrecords: true
            });

            $("#gridList").newtouchLocalDataGrid(null, mydata);
        };

        var mydata = [
               {
                   cfh: 'R20170417170000323', je: '90.00', ys: '吴翩', CreateTime: '2017-10-01 11:23:55'
               },
               {
                   cfh: 'R20170417180000324', je: '90.00', ys: '蒋朝凤', CreateTime: '2017-10-10 11:23:55'
               },
               {
                   cfh: 'R20170503140000325', je: '90.00', ys: '宁萍芳', CreateTime: '2017-10-21 11:23:55'
               }
        ];
     
        var myPreSearchInfo = function (data) {

        }
        //加载事件
        myPreSearchInfo.prototype.init = function (data) {
            if (!!!data.blh) {
                $("#blh").val("");
            } else {
                $("#blh").val(data.blh);
            }
            if (!!!data.kssj) {
                $("#kssj").val("");
            } else {
                $("#kssj").val(data.kssj);
            }
            if (!!!data.jssj) {
                $("#jssj").val("");
            } else {
                $("#jssj").val(data.jssj);
            }

            loadGrid(data);
        };

        return myPreSearchInfo;
    }());

    //jqGrid 双击选中某行
    function btn_edit() {
        PreSearchConfirm();
    }

    //确定 主页面调用
    function PreSearchConfirm() {
        DbClickGrid();
    }

    //双击
    function DbClickGrid() {
        var $gridList = $("#gridList");
        var patId = $gridList.jqGridRowValue().patId;
        var cfh = $gridList.jqGridRowValue().cfh;
        var obj = new Object();
        obj.patId = patId;
        obj.cfh = cfh;
        if (!!!obj.cfh) {
            $.modalMsg("请选择一个处方号", "warning");
            return;
        }
        prevWindow.getPatInfoAjax(obj);

        //关闭窗口
        ReceiptCancle();
    }

    //取消
    function ReceiptCancle() {
        $.modalClose();
    }


</script>




